// 列配置云存储
import { userConfigTableSubmit, userConfigTableGet } from '@/api/base/table'
export default {
  change({ tableId, options }) {
    userConfigTableSubmit({
      tableId,
      tableList: options.map(item => ({
        columnProp: item.prop,
        filterFlag: `${+!!item.filters}`,
        freezeFlag: `${+!!item.fixed}`,
        searchFlag: `${+!!item.screen}`,
        orderFlag: `${+!!item.sortable}`,
        hideFlag: `${+!!item.hide}`
      }))
    })
  },
  get({ tableId, columns, callback }) {
    userConfigTableGet({ tableId }).then(rsp => {
      const copyColumns = JSON.parse(JSON.stringify(columns))
      copyColumns.forEach(item => {
        const opt = rsp.data.data.find(o => o.columnProp === item.prop)
        if (!opt) return

        item.filters = opt.filterFlag === '1'
        item.fixed = opt.freezeFlag === '1'
        item.screen = opt.searchFlag === '1'
        item.sortable = opt.orderFlag === '1'
        item.hide = opt.hideFlag === '1'
      })
      callback && callback(copyColumns)
    })
  }
}
